home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_5.zip / adaed / gwudemos / phil.adb < prev    next >
Text File  |  1994-01-09  |  1KB  |  55 lines

  1. --::::::::::
  2. --phil.adb
  3. --::::::::::
  4. WITH Room;
  5. WITH Random;
  6. PACKAGE BODY Phil IS
  7.   
  8.   TASK BODY Philosopher IS
  9.   
  10.     Lifetime: CONSTANT := 5;
  11.  
  12.     Who_Am_I   : Positive;
  13.     First_Grab : Positive;
  14.     Second_Grab: Positive;
  15.     Meal_Time  : Natural;
  16.     Think_Time : Natural;
  17.     
  18.   BEGIN
  19.     ACCEPT Come_To_Life (My_ID :     Positive; 
  20.                         Chopstick1 : Positive;
  21.                         Chopstick2 : Positive) DO
  22.       Who_Am_I    := My_ID;
  23.       First_Grab  := Chopstick1;
  24.       Second_Grab := Chopstick2;
  25.  
  26.     END Come_To_Life;
  27.  
  28.     Room.Head_Waiter.Report_State(Who_Am_I, Breathing);
  29.  
  30.     FOR Meal IN 1..Lifetime LOOP
  31.  
  32.       Room.Sticks(First_Grab).Pick_Up;
  33.       Room.Head_Waiter.Report_State(Who_Am_I, Got_One_Stick, First_Grab);
  34.  
  35.       Room.Sticks(Second_Grab).Pick_Up;
  36.       Room.Head_Waiter.Report_State(Who_Am_I, Got_Other_Stick, Second_Grab);
  37.  
  38.       Meal_Time := Random.Random_Int(10);
  39.       Room.Head_Waiter.Report_State(Who_Am_I, Eating, Meal_Time);
  40.  
  41.       DELAY Duration(Meal_Time);
  42.       Room.Head_Waiter.Report_State(Who_Am_I, Done_Eating);
  43.  
  44.       Room.Sticks(First_Grab).Put_Down;
  45.       Room.Sticks(Second_Grab).Put_Down;
  46.  
  47.       Think_Time := Random.Random_Int(10);
  48.       Room.Head_Waiter.Report_State(Who_Am_I, Thinking, Think_Time);
  49.       DELAY Duration(Think_Time);
  50.  
  51.     END LOOP;
  52.  
  53.   END Philosopher;
  54.  
  55. END Phil;